<template>
  <basic-container class="box-shadow">
    <dataList
      :pageInfo="pager"
      placeholder="请输入物业名称"
      :listData="tableData"
      :selectData="selectDataArr"
      searchName="propertyName"
      :filterList="filterList"
      :menuList="['add', 'delete', { export: '导出' }]"
      @menu-click="handleMenuClick"
      openSelection
    >
      <el-table
        :data="tableData"
        @selection-change="$event => (selectDataArr = $event)"
        :header-cell-style="{
                    background: '#FAFAFA',
                    color: 'black'
                }"
      >
        <el-table-column type="selection" width="55"></el-table-column>
        <el-table-column label="物业类型" :formatter="dictVal_propertyTypes" prop="projectType"></el-table-column>
        <el-table-column label="物业名称" prop="propertyName"></el-table-column>
        <el-table-column label="物业地址" prop="projectAddr" show-overflow-tooltip></el-table-column>
        <el-table-column label="具体位置" prop="address"></el-table-column>
        <el-table-column label="巡查人" prop="inspectionPerson"></el-table-column>
        <el-table-column label="实际巡查日期" prop="inspectionDate"></el-table-column>
        <el-table-column label="巡查结果" prop="inspectionResult">
          <template slot-scope="scope">
            <span v-if="scope.row.inspectionResult == 0">达标</span>
            <span v-else>未达标</span>
          </template>
        </el-table-column>
        <el-table-column label="管理所" prop="manageUnit" :formatter="manageFormatter" show-overflow-tooltip />
        <el-table-column label="备注" prop="remarks"></el-table-column>
        <el-table-column width="125px" label="操作">
          <template slot-scope="scope">
            <el-link
              type="primary"
              :underline="false"
              @click="
                                showDetailsOfInspectionResults(
                                    'edit',
                                    scope.row
                                )
                            "
            >编辑</el-link>
          </template>
        </el-table-column>
      </el-table>
    </dataList>
    <el-dialog :title="title" :visible.sync="dialogVisible" width="80%" @close="close" :close-on-click-modal="false">
      <div style="font-weight: 700; height: 40px; font-size: 16px;">基本信息</div>
      <el-form ref="resultDetailsForm" :model="resultDetailsForm" :rules="rules" label-width="auto">
        <el-row type="flex" class="row-bg" justify="space-between" :gutter="20">
          <el-col :span="8">
            <el-form-item label="物业名称" prop="roomId">
              <el-select
                v-model="resultDetailsForm.roomId"
                filterable
                remote
                reserve-keyword
                :remote-method="remotePropertyNameMethod"
                placeholder="输入物业名称关键字获取列表"
                @change="propertyNameMonitoring($event)"
                :loading="loading"
              >
                <el-option v-for="(item, index) in options" :key="index" :label="item.label" :value="item.value">{{ item.label }}</el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="物业地址" prop="projectAddr">
              <el-input v-model="resultDetailsForm.projectAddr" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="具体位置" prop="address">
              <el-input v-model="resultDetailsForm.address" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex" class="row-bg" justify="space-between" :gutter="10">
          <el-col :span="8">
            <el-form-item label="使用单位" prop="useUnit">
              <el-select
                v-model="resultDetailsForm.useUnit"
                filterable
                remote
                reserve-keyword
                :remote-method="remoteUseUnitMethod"
                placeholder="输入单位名称关键字单位列表"
                :loading="loading"
              >
                <el-option v-for="(item, index) in unitList" :key="index" :label="item.value" :value="item.value">{{ item.value }}</el-option>
              </el-select>
              <!-- <el-input v-model="resultDetailsForm.useUnit"
                        :readonly="title == '编辑巡查结果'"
              placeholder="请输入"></el-input>-->
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="mobile">
              <el-input v-model.number="resultDetailsForm.mobile" :readonly="title == '编辑巡查结果'" @input="keyup" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="所属管理所" prop="manageUnit">
              <span></span>
              <span v-for="item in manageUnits" :key="item.value">
                <span v-if="resultDetailsForm.manageUnit == item.value">{{ item.label }}</span>
              </span>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="row-bg" justify="space-between" :gutter="20">
          <el-col :span="8" style="overflow: hidden;">
            <el-form-item label="预计巡查日期" prop="predictInspectionDate">
              <el-date-picker
                value-format="yyyy-MM-dd"
                v-model="
                                    resultDetailsForm.predictInspectionDate
                                "
                type="date"
                placeholder="选择日期"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="overflow: hidden;">
            <el-form-item label="实际巡查日期" prop="inspectionDate">
              <el-date-picker v-model="resultDetailsForm.inspectionDate" type="date" value-format="yyyy-MM-dd" placeholder="选择日期"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <!--业务要求   巡查人员指定当前登录账号 -->
            <el-form-item label="巡查人员" prop="inspectionPerson">
              <el-input v-model="resultDetailsForm.inspectionPerson" readonly placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row type="flex" class="row-bg" justify="space-between" :gutter="20">
          <el-col :span="8">
            <el-form-item label="巡查结果" prop="inspectionResult">
              <el-select v-model="resultDetailsForm.inspectionResult" filterable placeholder="-=请选择=-">
                <el-option label="达标" value="0"></el-option>
                <el-option label="不达标" value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="备注">
              <el-input v-model="resultDetailsForm.remarks" maxlength="10" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-tabs v-model="tabTitle">
        <el-tab-pane label="上报隐患记录" name="上报隐患记录">
          <el-table
            :data="resultDetailsForm.reportDangerRecord"
            :header-cell-style="{
                            'text-align': ' center'
                        }"
          >
            <el-table-column property="inspectionName" align="center" label="检查项目"></el-table-column>
            <el-table-column property="inspectionStandard" align="center" label="检查标准"></el-table-column>
            <el-table-column property="inspectResult" align="center" label="检查结果">
              <template slot-scope="scope">
                <el-switch
                  v-model="scope.row.inspectResult"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="0"
                  active-text="达标"
                  inactive-text="未达标"
                  inactive-value="1"
                ></el-switch>
              </template>
            </el-table-column>
            <el-table-column property="substandardContents" label="补充说明">
              <template slot-scope="scope">
                <el-input v-model="scope.row.substandardContents" placeholder="请输入"></el-input>
              </template>
            </el-table-column>
          </el-table>
        </el-tab-pane>
      </el-tabs>
      <h3 style="margin-top: 20px;">附件</h3>
      <el-divider></el-divider>
      <div v-if="dialogVisible">
        <v-upload
          type="file"
          ref="upload"
          :filterList="uploadFileList"
          :busId="resultDetailsForm.resultId"
          modelType="checkin"
          @onSuccess="onSuccess"
          v-model="uploadFileList"
          :canDelete="title==='编辑巡查结果'"
        />
      </div>
      <div style="width: 100% ; overflow: hidden;">
        <div style="float: right;">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="save()">保存</el-button>
        </div>
      </div>
      <!-- </div> -->
    </el-dialog>
  </basic-container>
</template>

<script src="./index.js"></script>

<style lang="scss" scoped>
.fl {
  float: left;
}

.fr {
  float: right;
}

.footer {
  overflow: hidden;
}

.header {
  overflow: hidden;
  margin-bottom: 10px;

  .fl {
    width: 60%;
  }
}
</style>
